//preamble 
clear
set more off

// Step 2: import the data from the InputData subfolder
import excel "Data/InputData/thesisdata.xlsx", sheet("Sheet1") firstrow

//generate squeeze period time variables, different windows for robustness
gen PRE_SQUEEZE1 = (DATE >= td(31dec2020) & DATE <= td(12jan2021))
gen SQUEEZE_PERIOD1 = (DATE >= td(13jan2021) & DATE <= td(27jan2021))
gen POST_SQUEEZE1 = (DATE >= td(28jan2021) & DATE <= td(19feb2021))

gen PRE_SQUEEZE2 = (DATE >= td(31dec2020) & DATE <= td(20jan2021))
gen SQUEEZE_PERIOD2 = (DATE >= td(21jan2021) & DATE <= td(27jan2021))
gen POST_SQUEEZE2 = (DATE >= td(28jan2021) & DATE <= td(19feb2021))

gen PRE_SQUEEZE3 = (DATE >= td(31dec2020) & DATE <= td(24jan2021))
gen SQUEEZE_PERIOD3 = (DATE >= td(25jan2021) & DATE <= td(27jan2021))
gen POST_SQUEEZE3 = (DATE >= td(28jan2021) & DATE <= td(19feb2021))

//convert RIC to numeric identifier, then declare panel data format
encode RIC, gen(company_id) 
xtset company_id DATE

//generate dummies that details extreme daily returns, multiple levels for robustness
gen SQUEEZE_10 = 1 if D_RETURN > .1
replace SQUEEZE_10 = 0 if SQUEEZE_10 == .
gen SQUEEZE_20 = 1 if D_RETURN > .2
replace SQUEEZE_20 = 0 if SQUEEZE_20 == .
gen SQUEEZE_30 = 1 if D_RETURN > .3
replace SQUEEZE_30 = 0 if SQUEEZE_30 == .
gen SQUEEZE_40 = 1 if D_RETURN > .4
replace SQUEEZE_40 = 0 if SQUEEZE_40 == .
gen SQUEEZE_50 = 1 if D_RETURN > .5
replace SQUEEZE_50 = 0 if SQUEEZE_50 == .
gen SQUEEZE_60 = 1 if D_RETURN > .6
replace SQUEEZE_60 = 0 if SQUEEZE_60 == .
gen SQUEEZE_70 = 1 if D_RETURN > .7
replace SQUEEZE_70 = 0 if SQUEEZE_70 == .
gen SQUEEZE_80 = 1 if D_RETURN > .8
replace SQUEEZE_80 = 0 if SQUEEZE_80 == .
gen SQUEEZE_90 = 1 if D_RETURN > .9
replace SQUEEZE_90 = 0 if SQUEEZE_90 == .
gen SQUEEZE_100 = 1 if D_RETURN > 1
replace SQUEEZE_100 = 0 if SQUEEZE_100 == .

//create logged variables
gen log_borrow_fee = log(BORROW_FEE)
gen log_return = log(D_RETURN)
gen log_volume = log(VOLUME)
gen log_loan_supply = log(LOAN_SUPPLY)
gen log_vix_close = log(VIX_CLOSE)

//save processed dataset
export excel using "`c(pwd)'/Data/AnalysisData/processed_data.xlsx", replace firstrow(variables)








